package file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopyMain {
	
	public static void main(String[] args) {
		
		File source = new File("C:\\java-master\\java.pdf");
		
		File dest = new File("C:\\java-master\\java-copy.pdf");
		
		FileInputStream in = null;
		FileOutputStream out = null;
		
		long start = System.currentTimeMillis();
		
		try {
			in = new FileInputStream(source);
			if (!dest.exists()) {
				dest.createNewFile();
			}
			out = new FileOutputStream(dest);
			int data = -1;
			while ((data = in.read()) != -1) {
				out.write(data);
			}
			
			System.out.println("파일이 복사되었습니다.");
		} catch (FileNotFoundException e) {
			System.err.println("파일이 없어 복사할 수 없습니다.");
		} catch (IOException e) {
			System.err.println("입출력 에러가 발생했습니다.");
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (IOException e) {}
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException e) {}
		}
		
		long end = System.currentTimeMillis();
		
		System.out.println("걸린 시간: " + (end - start) + " ms");
		
		
	}
	
}
